// 拼接HTTPUrl
function getUrl(type, pathname) {
  return window.RPConfig[type] + pathname;
}
const treeApi = {
  // 获取所有业务单元
  getTree: param => {
    return $http.post(getUrl('itShare', '/tree/list/page'), param)
  },

  // 查询树节点
  selectTreeNode: param => {
    return $http.post(getUrl('itShare', `/tree/node/select`), param).then(response => response.data);
  },

  // 根据父节点查询树节点
  queryTreeNode: nodeId => {
    return $http.post(getUrl('itShare', `/tree/node/list?nodeId=${nodeId}`)).then(response => response.data);
  },

  // 删除树节点
  // deleteTreeNode: params => {
  //   const { buCode, dcPeriod, treeCode, id } = params
  //   return $http.post(getUrl('itShare', `/dc/common/tree/node/delete?buCode=${buCode}&dcPeriod=${dcPeriod}&treeCode=${treeCode}`), [id]).then(response => response.data);
  // },
  // 删除组织节点
  deleteTreeNode: params => {
    return $http.post(getUrl('itShare', `/dc/common/org/node/delete`), params).then(response => response.data)
  },
  // 删除关键业务环节节点
  delKeyNode: params => {
    return $http.post(getUrl('itShare', `/dc/common/system/node/delete`), params).then(response => response.data)
  },

  // 查询树节点
  getTreeNodeDetail: param => {
    return $http.post(getUrl('itShare', `/tree/node/detail`), param).then(response => response.data);
  },

  // 更新树节点
  updateTreeNode: params => {
    const { buCode, dcPeriod, treeCode, ...recode } = params
    return $http.post(getUrl('itShare', `/dc/common/tree/node/update?buCode=${buCode}&dcPeriod=${dcPeriod}&treeCode=${treeCode}`), recode).then(response => response.data);
  },

  // 关联系统
  // connectSys: params => {
  //   return $http.post(getUrl('itShare', `/dc/common/tree/node/update`), params).then(response => response.data)
  // },

  // 新增树节点
  // addTreeNode: params => {
  //   const { buCode, dcPeriod, treeCode, ...recode } = params
  //   return $http.post(getUrl('itShare', `/dc/common/tree/node/add?buCode=${buCode}&dcPeriod=${dcPeriod}&treeCode=${treeCode}`), recode).then(response => response.data);
  // },
  // 新增组织节点
  addTreeNode: params => {
    return $http.post(getUrl('itShare', `/dc/common/org/node/add`), params)
  },
  // 新增关键业务环节节点
  addKeyNode: params => {
    return $http.post(getUrl('itShare', `/dc/common/system/node/add`), params)
  },

  // 根据nodePath 查询树
  getParentTreeByTreeNodePath: param => {
    return $http.get(getUrl('itShare', `/tree/getParentTreeByTreeNodePath`), param).then(response => response.data);
  },
  
  // 移除系统关联
  deleteSysConnect: params => {
    return $http.post(getUrl('itShare', `/dc/common/system/delete`), params).then(response => response.data)
  },
  // 关联系统
  connectSys: params => {
    return $http.post(getUrl('itShare', `/dc/common/system/add`), params).then(response => response.data)
  },
  // 根据值集代码、父级值key查询值集
  // GetValueSetByCodeAndParentKey: param => {
  //   return $http
  //     .get(`${window.RPConfig.setting}/valueset/item/list?vsCode=${param.code}&vsiParentKey=${param.parentKey}`, {})
  // }
  // 关键业务环节树
  // getKeyBisTree: treeCode => {
  //   return $http.post(`${window.RPConfig.mgt}/tree/findNodeTreeByTreeCode?treeCode=${treeCode}&recursion=true`)
  // },
  // 根据树编码获取整棵树
  getNodeTreeByTreeCode: treeCode => {
    return $http.post(getUrl('itShare', `/tree/findNodeTreeByTreeCode?treeCode=${treeCode}&recursion=true`)).then(response => response.data)
  }

}

export default treeApi
